﻿using Kingdee.BOS;
using Kingdee.BOS.Core.DynamicForm;
using Kingdee.BOS.Core.DynamicForm.PlugIn;
using Kingdee.BOS.Orm.DataEntity;
using Kingdee.BOS.Util;
using Kingdee.K3.Core.MFG.EntityHelper;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;

namespace Caraya.MFG.BusinessPlugIn
{
    /// <summary>
    /// 在表单->操作列表->对应操作代码->编辑->其他控制->服务插件注册
    /// 服务类插件对webapi操作生效
    /// </summary>
    [Description("生产领料保存测试"), HotUpdate]
    public class PickMtrlPlugIn : AbstractOperationServicePlugIn
    {
        public override void BeforeDoSaveExecute(BeforeDoSaveExecuteEventArgs e)
        {
            base.BeforeDoSaveExecute(e);
            DynamicObject[] dataEntities = e.DataEntities;
            foreach (DynamicObject dynamicObject in dataEntities)
            {
                var FindObject = dynamicObject.GetDynamicValue<DynamicObjectCollection>("Entity")
                    .Where(t => t.GetDynamicValue<DynamicObject>("MaterialId") != null)
                    .FirstOrDefault();
                var Material = FindObject.GetDynamicValue<DynamicObject>("MaterialId");
                var Specification = Material["Specification"] as LocaleValue;
                var MateSpec = Specification[2052];
                List<DynamicObject> list = (from x in dynamicObject.GetDynamicValue<DynamicObjectCollection>("Entity")
                                            where x.GetDynamicObjectItemValue("ActualQty", 0m) == 0m
                                            select x).ToList();
                DynamicObjectCollection dynamicObjectItemValue = dynamicObject.GetDynamicObjectItemValue<DynamicObjectCollection>("Entity");
                foreach (DynamicObject item in list)
                {
                    dynamicObjectItemValue.RemoveAt(dynamicObjectItemValue.IndexOf(item));
                }
            }
        }
        public override void InitializeOperationResult(IOperationResult result)
        {
            base.InitializeOperationResult(result);
        }
    }
}
